<template>
	<view class="content">
		<nav-bar ref="navBar" title="厨艺秀" :shadow="false">中奖记录</nav-bar>
        <!-- 公共组件-每个页面必须引入 -->
        <public-module></public-module>
        <mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
            <view class="lottery_list_box">
                <view class="lottery_table">
                    <view class="table_list" v-for="(item,index) of lotteryList" :key="index" :class="{black: index%2 == 0}">
                        <text>{{ item.giftTitle }}</text>
                        <text>{{ item.createTime }}</text>
                    </view>
                </view>
            </view>
        </mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/common/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		data() {
			return {
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				lotteryList: []
			};
		},
		//第一次加载
		onLoad(e) {
		},
		//页面显示
		onShow() {},
		//方法
		methods: {
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},
            /*下拉刷新的回调 */
            downCallback() {
            	//联网加载数据
            	this.loadData(1);
            },
            /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
            upCallback(page) {
            	//联网加载数据
            	this.loadData(page.num);
            },
            loadData(pageNo) {
                let httpData = {
                    pageNo: pageNo,
                    pageSize: 15,
                };
                this.$http
                	.post('api/turntable/v1/my_gift', httpData,{
                		load:false
                	}).then(res => {
                		uni.stopPullDownRefresh();
                		//方法一(推荐): 后台接口有返回列表的总页数 totalPage
                		this.mescroll.endByPage(res.data.length, res.pages); //必传参数(当前页的数据个数, 总页数)
                		
                		if (pageNo == 1) {
                			this.lotteryList = res.data;
                		} else {
                			this.lotteryList = this.lotteryList.concat(res.data);
                		}
                	}).catch(() => {
                		//联网失败, 结束加载
                		this.mescroll.endErr();
                	});
            },
		},
		//页面隐藏
		onHide() {},
		//页面卸载
		onUnload() {},
		//用户点击分享
		onShareAppMessage(e) {
			return this.wxShare();
		}
	};
</script>
<style lang="scss" scoped>
	@import "@/style/mixin.scss";

	.content {
		background-color: #FFFFFF;
		min-height: 100vh;
	}

	.lottery_list_box {
		padding: 5rpx 20rpx;

		.title {
			font-size: 28rpx;
			color: #333333;
		}
		.lottery_table{
			margin-top: 24rpx;
			border-right: solid 1rpx #e5e5e5;
			border-bottom: solid 1rpx #e5e5e5;
			.table_list {
				display: flex;
				border-top: solid 1rpx #e5e5e5;
			
				&.black text {
					background-color: #f7f7f7;
				}
			
				text {
					flex: 1;
					height: 81rpx;
					border-left: solid 1rpx #e5e5e5;
					background-color: #fff;
					font-size: 24rpx;
					color: #333333;
					line-height: 81rpx;
					text-align: center;
				}
			}
		}
	}
</style>
